<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ObjectUtils {
	
	public static function arrayToJSON($array) {
		return json_encode($array);
	}
	
	public static function jsonToArray($json){
		return json_decode($json);
	}
	
	public static function arrayToXML($array, $root_element_name){
		$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><{$root_element_name}></{$root_element_name}>"); 
	    $f = create_function('$f,$c,$a',' 
	            foreach($a as $k=>$v) { 
	                if(is_array($v)) { 
	                    $ch=$c->addChild($k); 
	                    $f($f,$ch,$v); 
	                } else { 
	                    $c->addChild($k,$v); 
	                } 
	            }'); 
	    $f($f,$xml,$ar); 
	    return $xml->asXML();
	}
}